import QueryList from '@/components/basicWidget/QueryList'
import { _delete } from '@/utils/requestUtil'
import React, { useRef } from 'react'
import { message } from 'antd'
import { Link } from 'react-router-dom'

/**
 * 黑名单管理
 * @author liu_jshan    
 * @version 1.0 20240331
 */
export default function BlackListManage(props) {

    const queryList = useRef(null)

    const actionColumns = (columns, data) => {
        columns.push({ title: '操作', dataIndex: 'operate' })
        data = data.map(item => {
            item.operate = (
                <Link onClick={async () => {
                    const response = await _delete(`/auth/remove/${item.ip}/blackList`)
                    if (response && response.code === 200) {
                        message.success('操作成功')
                        await queryList.current.onQuery()
                    }
                }}>解封</Link>
            )
            return item
        })
        return { newColumns: columns, newData: data }
    }

    return (
        <QueryList
            queryCode='blackListManage'
            actionColumns={actionColumns}
            ref={queryList}
        >
        </QueryList>
    )
}
